<template>
  <div class="user-pwd">
	  掉了验证手机号这一步，得先请求api/consumer/verifyPhone
    <el-form
      :model="ruleForm"
      :rules="rules"
	   status-icon
      ref="ruleForm"
    >
      <el-form-item label="新密码" prop="password">
        <el-input
          type="password"
          v-model="ruleForm.password"
          placeholder="请输入新密码"
          autocomplete="off"
          ref="old_password"
        ></el-input>
      </el-form-item>
      <center>
		  <van-button color="linear-gradient(to right, #4bb0ff, #1989fa)" class="btn"  @click="submitForm('ruleForm')">提交</van-button>
      </center>
    </el-form>
  </div>
</template>
<script>
export default {
  name: "updatePwd",
  data() {
    return {
      ruleForm: {
		  password:''
	  },
      rules: {
        password: [
          { required: true, message: "请输入新密码", trigger: "blur" },
          { min: 6, max:12,message: "密码长度为6-12位", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    goBack() {
      this.$router.go(-1);
    },
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.$axios
            .put(
              "/api/consumer/pwd/reset",{
                password: this.ruleForm.password
              }
            )
            .then(res => {
              if (res.data.code == 200) {
                this.$toast("密码重置成功");
                //this.$store.commit("delUser");
                this.$router.push({ path: "/" });
              }else{
				  this.$toast(res.data.message);
			 }
            })
            .catch(err => {
              this.$toast("操作失败，请重试");
            });
        } else {
          this.$toast("请按要求填写密码");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    changOldPwdfouce() {
      this.$nextTick(x => {
        //正确写法
        this.$refs.old_password.focus();
      });
    }
  }
};
</script>
<style lang="less">
.user-pwd {
  .el-form {
	  margin: 0 5%;
    width: 90%;
  }
  .btn{
	  width: 90%;
  }
}
</style>